package ctm.javacode;

import java.security.MessageDigest;
import java.util.Random;

import org.apache.commons.codec.digest.DigestUtils;

public class md5Encrypt {
	
	public static String generate(String pass){
		String md5 = DigestUtils.md5Hex(pass);
		return md5;
	}
	
	
	/*public static void main(String argv[]) throws Exception{
		String passwd = "89471345";
		boolean option = true;
		MessageDigest m = MessageDigest.getInstance("MD5");
		Random rand = new Random();
		byte[] saltarray = new byte[12];
		String salt = "";
		String result = "";

		rand.nextBytes(saltarray);
		m.update(saltarray);
		m.update(passwd.getBytes("UTF8"));
		byte s[] = m.digest();

		for (int i = 0; i < s.length; i++) {
		result += Integer.toHexString((0x000000ff & s[i]) | 0xffffff00).substring(6); }
		for (int i = 0; i < saltarray.length; i++) {
		salt += saltarray[i] + ","; }

		if(option) {System.out.println(result); }
		else { System.out.println(salt);  } 
		
		
		String temp = getRandomKeyt(6);
		System.out.println(temp);	
	}*/

	/*public static void main(String argv[]) throws Exception{
		String pass = "89471345";
		String salt = getRandomKeyt(6);
		System.out.println(salt);
		String md5 = DigestUtils.md5Hex(salt+pass);
		System.out.println(md5);
	}*/
	
	/*private static String getRandomKeyt(int length) throws Exception{
      if (length < 1)
          throw new Exception("密钥长度不能小于 1");
      String _keyt = "";
      for (int i = 0; i < length; i++) {
          _keyt += (char) (33 + (int) (Math.random() * (126 - 33 + 1)));
      }
      return _keyt;
	}*/
}

